package com.example.neusoft.yuejian_12.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian_12.JavaBean.Club;
import com.example.neusoft.yuejian_12.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by admin on 2017/11/10.
 */

public class ClubMasterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public ClubMasterAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.clubmaster_item, parent, false);
        return new ClubMasterAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final Club.ClubteacherEntity entity = (Club.ClubteacherEntity) mDataList.get(position);

        if (null == entity)
            return;
        ClubMasterAdapter.ViewHolder viewHolder = (ClubMasterAdapter.ViewHolder) holder;
        viewHolder.name.setText(entity.getName());
        if(!entity.getThumb().isEmpty())
        {
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+entity.getThumb()).into(viewHolder.pic);
        }
        else
        {
            viewHolder.pic.setImageResource(R.drawable.qya);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView pic;
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.master_name);
            pic = (ImageView) itemView.findViewById(R.id.master_pic);
        }
    }
}


